package tt.com.common.util;

import tt.com.common.annotation.IsNull;
import tt.com.common.model.DriveTask;

import java.lang.reflect.Field;

public class ObjectUtil {

    //

    /**
     * 判断传入对象的属性是否为空
     * @param t 需要判断的对象
     * @return 返回是否为空 true 表示不为空，false 为空
     */
    public static boolean objectIsNull(Object t){
        boolean flag = true;
        Class<?> cla = t.getClass();
        Field[] fields = cla.getDeclaredFields();
        for (Field item : fields) {
            item.setAccessible(true);
            boolean present = item.isAnnotationPresent(IsNull.class);
            if (!present)
                continue;
            Object o = null;
            try {
                o = item.get(t);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            if (o == null || o.equals("")){
                flag = false;
                break;
            }
        }
        return flag;
    }

    public static void main(String[] args) {
        DriveTask task = new DriveTask();
        task.setRelationName("");
        System.out.println(objectIsNull(task));
    }
}
